Ensure all property types are translated when converting function calls to a2a#657
Ensure all property types are translated when converting function calls to a2a#657zbirkenbuel wants to merge 3 commits into
Conversation
…ls to a2a Python and Go implementations of ADK both copy function call and response properties by copying the entire struct automatically. Java does this a property at a time and so was missing the "id" property of the ADK event. Providing these allows downstream agents to properly associate multiple tool calls and responses to the same tool name.
Summary of ChangesHello @zbirkenbuel, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical inconsistency in the Java ADK's handling of function call and response properties. Previously, the 'id' property, essential for correlating tool calls and responses, was not being properly translated, unlike its Python and Go counterparts. The changes ensure that this 'id' property is now correctly processed, leading to more robust and reliable communication between agents and tools within Java applications. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly adds the id property to FunctionCall and FunctionResponse during A2A conversions, which aligns the Java implementation with others and enables better tool call tracking. The changes are well-implemented and include corresponding test updates to ensure correctness. I've added one suggestion to refactor a small piece of duplicated code for improved maintainability.
| if (data.containsKey("name") && data.containsKey("args") | ||
| || A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL.equals(metadataType)) { | ||
| String functionName = String.valueOf(data.getOrDefault("name", "")); | ||
| String functionId = String.valueOf(data.getOrDefault("id", "")); | ||
| Map<String, Object> args = coerceToMap(data.get("args")); | ||
| return Optional.of( | ||
| com.google.genai.types.Part.builder() | ||
| .functionCall(FunctionCall.builder().name(functionName).args(args).build()) | ||
| .functionCall(FunctionCall.builder().name(functionName).id(functionId).args(args).build()) | ||
| .build()); | ||
| } | ||
|
|
||
| if (data.containsKey("name") && data.containsKey("response") | ||
| || A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE.equals(metadataType)) { | ||
| String functionName = String.valueOf(data.getOrDefault("name", "")); | ||
| String functionId = String.valueOf(data.getOrDefault("id", "")); | ||
| Map<String, Object> response = coerceToMap(data.get("response")); | ||
| return Optional.of( | ||
| com.google.genai.types.Part.builder() | ||
| .functionResponse( | ||
| FunctionResponse.builder().name(functionName).response(response).build()) | ||
| FunctionResponse.builder().name(functionName).id(functionId).response(response).build()) | ||
| .build()); | ||
| } |
There was a problem hiding this comment.
These two if blocks for handling function calls and function responses contain duplicated logic for extracting functionName and functionId. To improve code clarity and reduce redundancy, you could extract these variable assignments before the conditional checks.
String functionName = String.valueOf(data.getOrDefault("name", ""));
String functionId = String.valueOf(data.getOrDefault("id", ""));
if (data.containsKey("name") && data.containsKey("args")
|| A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL.equals(metadataType)) {
Map<String, Object> args = coerceToMap(data.get("args"));
return Optional.of(
com.google.genai.types.Part.builder()
.functionCall(FunctionCall.builder().name(functionName).id(functionId).args(args).build())
.build());
}
if (data.containsKey("name") && data.containsKey("response")
|| A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE.equals(metadataType)) {
Map<String, Object> response = coerceToMap(data.get("response"));
return Optional.of(
com.google.genai.types.Part.builder()
.functionResponse(
FunctionResponse.builder().name(functionName).id(functionId).response(response).build())
.build());
}…ls to a2a Python and Go implementations of ADK both copy function call and response properties by copying the entire struct automatically. Java does this a property at a time and so was missing the "id" property of the ADK event. Providing these allows downstream agents to properly associate multiple tool calls and responses to the same tool name.
Python and Go implementations of ADK both copy function call and response properties by copying the entire struct automatically. Java does this a property at a time and so was missing the "id" property of the ADK event. Providing these allows downstream agents to properly associate multiple tool calls and responses to the same tool name.